<!-- Edit Modal //-->
<div id="editModal" class="reveal-modal small" data-reveal>
	<div id="edit"></div>
 </div>
<!-- End Edit Modal //-->

<!-- Atur Modal //-->
<div id="aturModal" class="reveal-modal small" data-reveal>
	<div id="atur"></div>
 </div>
<!-- End Atur Modal //-->

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default kotakwidget">
			<div class="panel-heading kepalakotakwidget">
				Jabatan aktif saat ini
			</div>
				
				<div class="panel-body">
					<div class="row">
						<div class="col-md-12">
							<div id="contentAturJabatan">
							<table class="table table-condensed">
							  <thead>
								<tr>
									<th>#</th>
									<th>Jabatan</th>
									<th>Nama Pegawai</th>									
									<th>Periode</th>						
									<th>Masa Jabatan</th>			
								</tr>
							  </thead>
							  <tbody>
								<?php
									$i =1; 
									foreach ($list as $row) {
								?>
								<tr class="hover t-hijau-dark">
									<td width="30"><?php echo $i++ ?></td>
									<td><?php echo $row->jabatan; ?></td>
									<td><?php echo $row->nama_lengkap; ?></td>									
									<td><?php echo date('d/m/Y', strtotime($row->mulai));?> <i class="fa fa-arrow-right"></i> <?php echo date('d/m/Y', strtotime($row->akhir));?></td>									
									<td>
										<?php echo selisihTgl($row->mulai,$row->akhir);?>
										<a onClick="edit_jabatan('<?php echo $row->id_a_jabatan;?>')" class="editorLink pull-right" data-reveal-id="editModal" nama="<?php echo $row->nama_lengkap; ?>" 2nd="<?php echo $row->jabatan; ?>" hpid="<?php echo $row->id_a_jabatan;?>" title="Edit Jabatan <?php echo $row->jabatan; ?>" data-reveal><span class="glyphicon glyphicon-edit"></span></a>
									</td> 
								</tr>
								<?php
									}
								?>

								<?php 
									$n = count($list)+1;
									foreach ($list_j as $rowj) {
								?>
								<tr class="hover">
									<td width="30"><?php echo $n++ ?></td>
									<td><?php echo $rowj->jabatan; ?></td>
									<td>Belum diatur</td>
									<td>Belum diatur</td>
									<td>
										Belum diatur
										<a onClick="atur_jabatan('<?php echo $rowj->id_m_jabatan;?>')" class="editorLink pull-right" data-reveal-id="aturModal" data-reveal title="Atur Jabatan <?php echo $rowj->jabatan; ?>"><span class="glyphicon glyphicon-cog"></span></a>
									</td>
								</tr>
								<?php
									}
								?>
							  </tbody>
							</table>
							</div>
						</div>
					</div>
				</div>
		</div>
	</div>	
</div>
<!-- /#page-wrapper -->
<script>
// Edit
function edit_jabatan(id_a_jabatan){
	$.ajax({
		type: "POST",
		url : "<?php echo site_url(); ?>a_jabatan/edit",
		data: "id_a_jabatan="+id_a_jabatan,
		cache: false,
		success: function(response) {
			$('#edit').html(response);
		}
	});
	return false;
}
// Atur
function atur_jabatan(id_m_jabatan){
	$.ajax({
		type: "POST",
		url : "<?php echo site_url(); ?>a_jabatan/atur",
		data: "id_m_jabatan="+id_m_jabatan,
		cache: false,
		success: function(response) {
			$('#atur').html(response);
		}
	});
	return false;
}
// Ajax Complete
$(document).ajaxComplete(function(){
	// Datepicker
	$('.input-daterange').datepicker({
		format: "dd/mm/yyyy",
	    language: "id",
	    todayHighlight: true
	});
	// Update
	$('#UpdateAturJabatan').bind('submit', function(event) {
		var link = $(this).attr('action');
		$.ajax({
			url: link,
			type: "POST",
			data: $(this).serialize(),
			cache: false,
			beforeSend: function(){
				$('#errorUpdate').hide();
				$('#loadingUpdate').show();
			},          
			success: function() {
				var $container = $("#contentAturJabatan");
				$container.load("<?php echo site_url(); ?>a_jabatan/refresh");
				
				$('#loadingUpdate').hide();
				$('#editModal').foundation('reveal', 'close');
			},
			error:function(){
				$('#loadingUpdate').hide();
				$('#errorUpdate').show();
			}
		});
		return false; // dont post it automatically
	});
	// Save/Atur
	$('#SaveAturJabatan').bind('submit', function(event) {
		var link = $(this).attr('action');
		$.ajax({
			url: link,
			type: "POST",
			data: $(this).serialize(),
			cache: false,
			beforeSend: function(){
				$('#errorAdd').hide();
				$('#loadingAdd').show();
			},          
			success: function() {
				var $container = $("#contentAturJabatan");
				$container.load("<?php echo site_url(); ?>a_jabatan/refresh/");
				
				$('#loadingAdd').hide();
				$('#aturModal').foundation('reveal', 'close');
			},
			error:function(){
				$('#loadingAdd').hide();
				$('#errorAdd').show();
			}
		});
		return false; // dont post it automatically
	});
});
</script>